{extend name='bus@public/index'}
{block name="css"}{/block}
{block name="main"}
<style>
    .col-md-2{
        max-width:11.666% !important;
    }
    select{
        height:31px !important;
    }
</style>
<div class="ibox-title">
    <h5>用户管理</h5>
    <div class="pull-right mt-2" data-button>
    </div>
</div>
<div class="container-fluid " style="margin-top:20px;" ng-controller="UserIndexController">
    <!-- 表单搜索 -->
    <div class="form-row mb-2 mt-2">

        <div class="col-md-2">
            <div class="input-group input-group-sm">
                <div class="input-group-prepend">
                    <span class="input-group-text">部门</span>
                </div>
                <select class="form-control" name="department_id" id="department_id" ng-model="model.department_id"
                        ng-options="o.id as o.name for o in department"></select>
            </div>
        </div>

        <div class="col-md-2">
            <div class="input-group input-group-sm">
                <div class="input-group-prepend">
                    <span class="input-group-text">职位</span>
                </div>
                <select class="form-control" name="position_id" id="position_id" ng-model="model.position_id"
                        ng-options="o.id as o.name for o in position"></select>
            </div>
        </div>

        <div class="col-md-2">
            <div class="input-group input-group-sm">
                <div class="input-group-prepend">
                    <span class="input-group-text">角色</span>
                </div>
                <select class="form-control" name="role_id" id="role_id" ng-model="model.role_id"
                        ng-options="o.id as o.name for o in role"></select>
            </div>
        </div>

        <div class="col-md-2">
            <div class="input-group input-group-sm">
                <div class="input-group-prepend">
                    <span class="input-group-text">状态</span>
                </div>
                <select class="form-control" name="status" id="status" ng-model="model.status"
                        ng-options="o.id as o.name for o in status"></select>
            </div>
        </div>

        <div class="col-md-2">
            <div class="input-group input-group-sm">
                <div class="input-group-prepend">
                    <span class="input-group-text">更多搜索</span>
                </div>
                <input class="form-control " name="key" id="key" autocomplete="off" ng-model="model.key">
            </div>
        </div>

        <div class="form-group">
            <button type="button" class="btn btn-info btn-sm" id="search"><i class="fa fa-search"></i> 搜索</button>
        </div>
    </div>
    <!-- 数据表格 -->
    <table id="data_list" title="用户管理"></table>

</div>


{/block}
{block name="script"}
<script>
    let PageConfig = {
        InfoUrl: '/admin/user/info',
        DeleteUrl: '/admin/user/delete',
        WhiteUrl: 'admin/user/white',
        BlackUrl: 'admin/user/black',
        TemplateUrl: '',
        Area: ['650px', '350px'],
        TableId: 'data_list',
        GetListUrl: '/admin/user/data_list',
        TableColumns: [
            {field: '', checkbox: true, align: 'center', valign: 'middle', width: IdWidth},
            {title: '账号', field: 'account', align: 'center', valign: 'middle', width: AccountWidth, sortable: true,},
            {title: '姓名', field: 'name', align: 'center', valign: 'middle', width: UserNameWidth, sortable: true,},
            {title: '状态', field: 'status', align: 'center', valign: 'middle', width: StatusWidth, sortable: true,},
            {title: '角色', field: 'role_name', align: 'center', valign: 'middle', width: RoleNameWidth, sortable: true,},
            {title: '部门', field: 'department_name', align: 'center', valign: 'middle', width: DepartmentNameWidth, sortable: true,},
            {title: '职位', field: 'position_name', align: 'center', valign: 'middle', width: PositionNameWidth, sortable: true,},
            {title: '性别', field: 'sex', align: 'center', valign: 'middle', width: SexWidth, sortable: true, visible: false},
            {title: '年龄', field: 'age', align: 'center', valign: 'middle', width: AgeWidth, sortable: true, visible: false},
            {title: '电话', field: 'mobile', align: 'center', valign: 'middle', width: MobileWidth, sortable: true,},
            {title: '供应商', field: 'remark', formatter: frame.tips(20), width: RemarkWidth, sortable: true,},
            {title: '创建人 ', field: 'create_user', align: 'center', valign: 'middle', width: UserNameWidth, sortable: true,},
            {title: '创建日期', field: 'create_time', align: 'center', valign: 'middle', width: DateTimeWidth, sortable: true,},
            {title: '最近登录IP', field: 'last_login_ip', align: 'center', valign: 'middle', width: IPWidth, sortable: true,},
            {title: '最近登录日期', field: 'last_login_date', align: 'center', valign: 'middle', width: DateTimeWidth, sortable: true,},
        ],
        PowerUrl: '/admin/user/funcpower'

    }
</script>
<script>
    app.controller("UserIndexController", function ($scope, $http, dataFactory) {
        //绑定下拉框
        $scope.department = [];
        $scope.role = [];
        $scope.position = [];
        $scope.status = [];
        dataFactory.SelectDepartment().then(function (data) {
            $scope.department = data;
        });
        dataFactory.SelectRole().then(function (data) {
            $scope.role = data;
        });
        dataFactory.SelectPosition().then(function (data) {
            $scope.position = data;
        });
        dataFactory.SelectStatus().then(function (data) {
            $scope.status = data;
        });
        $scope.model = {
            department_id: 0,
            position_id: 0,
            role_id: 0,
            status: '',
            key: '',
        };
        $(function () {
            //初始化表格
            let table = new TableInit($scope);
            table.Init();
        });

    });


    //功能权限
    function funcpower() {
        let rows = $('#' + PageConfig.TableId).bootstrapTable("getAllSelections");
        if (rows.length == 0) {
            oob.showIframe({code: -1, msg: "您没有选中任何项,请您选中后再操作。"});
            return false;
        }
        if (rows.length > 1) {
            oob.showIframe({code: -1, msg: "很抱歉,一次只能选择一条记录。"});
            return false;
        }
        parent.layer.open({
            title: '功能权限设置', type: 2, area: ['800px', '95%'], fix: true, maxmin: false
            , content: PageConfig.PowerUrl + '?id=' + rows[0]['id'],
        });
    }

    //禁用
    function disable() {
        let rows = $('#' + PageConfig.TableId).bootstrapTable("getAllSelections");
        if (rows.length == 0) {
            oob.showIframe({code: -1, msg: "您没有选中任何项,请您选中后再操作。"});
            return false;
        }
        if (rows.length > 1) {
            oob.showIframe({code: -1, msg: "很抱歉,一次只能选择一条记录。"});
            return false;
        }
        parent.layer.confirm('你确定要禁用吗？', {
            btn: ['确定', '取消']
        }, function () {
            oob.ajaxIframe({
                url: "/admin/user/disable",
                type: "post",
                data: {
                    id: rows[0]['id'],
                },
            }).then(function (data) {
                oob.showIframe(data, function () {
                    if (data.code == 0) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        bind();
                    }
                });
            });
        });
    }

    //启用
    function enable() {
        let rows = $('#' + PageConfig.TableId).bootstrapTable("getAllSelections");
        if (rows.length == 0) {
            oob.showIframe({code: -1, msg: "您没有选中任何项,请您选中后再操作。"});
            return false;
        }
        if (rows.length > 1) {
            oob.showIframe({code: -1, msg: "很抱歉,一次只能选择一条记录。"});
            return false;
        }
        parent.layer.confirm('你确定要启用吗？', {
            btn: ['确定', '取消']
        }, function () {
            oob.ajaxIframe({
                url: "/admin/user/enable",
                type: "post",
                data: {id: rows[0]['id']},
            }).then(function (data) {
                oob.showIframe(data, function () {
                    if (data.code == 0) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        bind();
                    }
                });
            });
        });
    }
    //一键白班
    function white() {
        let rows = $('#' + PageConfig.TableId).bootstrapTable("getAllSelections");
        if (rows.length == 0) {
            oob.showIframe({code: -1, msg: "您没有选中任何项,请您选中后再操作。"});
            return false;
        }
        let data = [];
        let rowsLength = rows.length;
        for (let i = 0; i < rowsLength; i++) {
            data.push(rows[i]["id"]);
        }
        parent.layer.confirm('确认要分配这' + data.length + '条选中的行吗？', {
            btn: ['确定', '取消']
        }, function () {
            oob.ajaxIframe({
                url: '/admin/user/white',
                type: "post",
                data: {ids: data},
            }).then(function (data) {
                oob.showIframe(data, function () {
                    if (data.code == 0) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        bind();
                    }
                })
            });
        });
    }
    //一键晚班
    function black() {
        let rows = $('#' + PageConfig.TableId).bootstrapTable("getAllSelections");
        if (rows.length == 0) {
            oob.showIframe({code: -1, msg: "您没有选中任何项,请您选中后再操作。"});
            return false;
        }
        let data = [];
        let rowsLength = rows.length;
        for (let i = 0; i < rowsLength; i++) {
            data.push(rows[i]["id"]);
        }
        parent.layer.confirm('确认要分配这' + data.length + '条选中的行吗？', {
            btn: ['确定', '取消']
        }, function () {
            oob.ajaxIframe({
                url: '/admin/user/black',
                type: "post",
                data: {ids: data},
            }).then(function (data) {
                oob.showIframe(data, function () {
                    if (data.code == 0) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                        bind();
                    }
                })
            });
        });
    }
</script>
{/block}



